<?php


namespace App\Models;

/**
 * 余额记录明细
 * Class CreditLog
 *
 * @package App\Models
 * @property int $id
 * @property int $order_id 订单id
 * @property int $uid 用户id
 * @property int $log_type 日志类型
 * @property int $type 积分类型,1余额 2积分
 * @property string $num 数量
 * @property string $give_money 赠送金额
 * @property int $give_credit 赠送积分
 * @property string $presentcredit 当前数量
 * @property string $give_presentcredit 当前赠送数量
 * @property string $remark 备注
 * @property int $operator 后台操作员id
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog query()
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereGiveCredit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereGiveMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereGivePresentcredit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereLogType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereOperator($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog wherePresentcredit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CreditLog whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property-read mixed $title
 * @property-read \App\Models\User $user
 */
class CreditLog extends BaseModel
{
    protected $dateFormat = 'U';
    protected $guarded = [];
    protected $appends = ['title'];

    /**
     * 日志类型
     * @var array
     */
    public static $logType = [
        //充值明细from对应
        1 => '现金充值',
        2 => '系统充值',
        3 => '系统扣款',
        10 => '下单支付',
        21 => '充值退款扣余额',
        22 => '余额提现',
        23 => '余额提现驳回',
        24 => '配送结算'
    ];

    public function getCreatedAtAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    public function getTitleAttribute()
    {
        return self::$logType[$this->log_type];
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'id');
    }
}